#!/usr/bin/env python

import os
import sys

from tools.gpick import *

Import('*')
local_env = env.Clone()

if not local_env.GetOption('clean') and not env['TOOLCHAIN'] == 'msvc':
	local_env.ParseConfig('pkg-config --cflags --libs $GTK_PC')
	local_env.ParseConfig('pkg-config --cflags --libs $LUA_PC')
	if env['DOWNLOAD_RESENE_COLOR_LIST']:
		local_env.ParseConfig('pkg-config --libs $CURL_PC')

if local_env['ENABLE_NLS']:
	local_env.Append(
		CPPDEFINES = ['ENABLE_NLS'],
	)

sources = local_env.Glob('*.cpp') + local_env.Glob('dynv/*.cpp') + local_env.Glob('transformation/*.cpp')

objects = []
objects.append(SConscript(['version/SConscript'], exports='env'))
objects.append(SConscript(['gtk/SConscript'], exports='env'))
objects.append(SConscript(['layout/SConscript'], exports='env'))
objects.append(SConscript(['internationalisation/SConscript'], exports='env'))
objects.append(SConscript(['dbus/SConscript'], exports='env'))
objects.append(SConscript(['tools/SConscript'], exports='env'))

if env['EXPERIMENTAL_CSS_PARSER']:
	parser_objects, generated_files = SConscript(['cssparser/SConscript'], exports='env')
	objects.append(parser_objects)
else:
	generated_files = []

objects.append(SConscript(['color_names/SConscript'], exports='env'))

if env['TOOLCHAIN'] == 'msvc':
	local_env.Append(LIBS = ['glib-2.0', 'gtk-win32-2.0', 'gobject-2.0', 'gdk-win32-2.0', 'cairo', 'gdk_pixbuf-2.0', 'lua5.2', 'expat2.1', 'pango-1.0', 'pangocairo-1.0', 'intl'])

if local_env['BUILD_TARGET'] == 'win32':
	if not (env['TOOLCHAIN'] == 'msvc'):
		local_env.Append(LINKFLAGS = '-mwindows')
		local_env.Append(LIBS=['expat'])
	else:
		local_env.Append(LINKFLAGS = ['/SUBSYSTEM:WINDOWS', '/ENTRY:mainCRTStartup'], CPPDEFINES = ['XML_STATIC'])
	objects.append(SConscript(['winres/SConscript'], exports='env'))
elif local_env['BUILD_TARGET'] == 'linux2':
	local_env.Append(LIBS=['rt', 'expat'])

executable = local_env.Program(
	'gpick',
	source = [sources, objects])

Return('executable', 'generated_files')

